package cn.ffcs.util.tag;

import java.util.Date;
import java.util.Map;

import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;

import cn.ffcs.security.model.UserResource;
import cn.ffcs.security.web.UserContext;
import cn.ffcs.util.context.Constant;

/**
 * 
 * 权限标签<br/> <table>
 * <tr>
 * <td>负责人/principal: </td>
 * <td colspan="2">liuzhh</td>
 * <tr>
 * <td>修改记录/revision:</td>
 * <td colspan="2"></td>
 * </tr>
 * <tr>
 * <td>日期:</td>
 * <td>修改人:</td>
 * <td>修改说明:</td>
 * </tr>
 * <tr>
 * <td></td>
 * <td></td>
 * <td></td>
 * </tr>
 * </table>
 * @author liuzhh
 * @version $Id$
 */
public class SecurityTag extends TagSupport
{
    /** 网络标识 */
    private static final long serialVersionUID = 7505161443414678050L;

    private String code;
    
    private String resType;
    
    public int doStartTag() throws JspTagException
    {
        UserContext userContext = (UserContext) pageContext.getSession()
                .getAttribute(Constant.LOGIN_USER_CONTEXT_);

        Map<String, UserResource> urs = userContext.getDispatchResources();
        UserResource ur = urs.get(resType + code);
        String showStr = "";
        if (ur == null) return this.SKIP_BODY;
//        pageContext.getOut().write(showStr);

        return EVAL_BODY_INCLUDE;

    }

    public int doEndTag() throws JspTagException
    {
        String dataString = new Date().toString();
        try
        {
        }
        catch (Exception e)
        {
            throw new JspTagException(
                    "Fatal error:tag conld not write to JSP out");
        }
        return EVAL_PAGE;
    }

    /**
     * @return the code
     */
    public String getCode()
    {
        return code;
    }

    /**
     * @param code the code to set
     */
    public void setCode(String code)
    {
        this.code = code;
    }

    /**
     * @return the resType
     */
    public String getResType()
    {
        return resType;
    }

    /**
     * @param resType the resType to set
     */
    public void setResType(String resType)
    {
        this.resType = resType;
    }
}
